/**
 * @Project : ProgrammingExercises
 * @Package : Leetcode
 * @File : Q1646.java
 * @Author : WangRuoyu
 * @Date 2023/1/12 16:32
 */

package leetcode;

public class Q1646 {
    public int getMaximumGenerated(int n) {
        if (n == 0 || n == 1) {
            return n;
        }
        int[] f = new int[n + 1];
        int res = 0;
        f[0] = 1;
        f[1] = 1;
        for (int i = 2; i <= n; i++) {
            if (i % 2 == 0) {
                f[i] = f[i / 2];
            } else {
                f[i] = f[(i - 1) / 2] + f[((i - 1) / 2) + 1];
            }
            res = Math.max(f[i], res);
        }

        return res;
    }

    public static void main(String[] args) {
        Q1646 sl = new Q1646();
        int n = 7;
        System.out.println(sl.getMaximumGenerated(n));
    }
}
